home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-08 | 38.5 KB | 1,150 lines | [TEXT/CWIE] |
- //
- // GrayCouncil
- // Copyright ©1996 by Trygve Isaacson. All Rights Reserved.
- //
- // Before using any of the GrayCouncil source code, read and
- // follow the licensing info in the accompanying documentation
- // or contact:
- // <trygve@kagi.com>
- // <http://www.kagi.com/authors/trygve/>
- //
- // Classes defined below:
- // AGAObject -- abstract base class for most others
- // MExclusiveObject -- mixin class for mutual exclusivity (e.g. radio)
- // AGATextStyle -- text style attributes container
- // AGAStaticText -- simple string object
- // AGAPushButton -- push button with auto default outline capability
- // AGACheckBox -- check box with mixed state capability
- // AGARadioButton -- radio button with mixed state capability
- // MIconButtonObject -- mixin class for icon buttons
- // AGAIconPushButton -- AGAPushButton subclass for icon push buttons
- // AGAIconCheckBox -- AGACheckBox subclass for on/off icon buttons
- // AGAIconRadioButton -- AGARadioButton subclass for mutually exclusive
- // on/off icon buttons
- // AGATrackingIndicator -- abstract superclass for scroll bar and slider
- // AGAScrollBar -- scroll bar with 32-bit values, live tracking, and
- // proportional indicator capabilities
- // AGASlider -- slider with pointy or rectangular indicator, optional
- // labels, live tracking, proportional indicator capabilities
- // AGAPopupMenu -- popup menu with optional title
- // AGALittleArrows -- little up/down arrows with notification
- // AGADisclosureTriangle -- disclosure triangle with animation
- // AGAProgressIndicator -- determinate or indeterminate progress gauge
- // with moving determinate origin capability
- // AGASeparator -- separator line with automatic directionality
- // AGAGroupBox -- primary or secondary group box with optional title or
- // room for external title or control
- //
-
- #ifndef __GRAYCOUNCIL__
- #define __GRAYCOUNCIL__
-
- #define kGrayCouncilCopyright "\pGray Council ©1996 by Trygve Isaacson. All Rights Reserved."
-
- #include <stl.h>
-
- //
- // You must call InitGrayCouncil after initializing the Toolbox
- // and before instantiating any GrayCouncil objects. This routine
- // is called automatically if you call the framework-specific
- // initializer. If it returns an error, you should quit. The only
- // current error situation of this is an out-of-memory condition
- // during initialization.
- //
-
- extern OSErr InitGrayCouncil();
-
- //
- // AGAObject ---------------------------------------------------------------
- //
- // All of the visual GrayCouncil objects inherit from AGAObject.
- //
- // In general, all you have to do with any AGAObject is instantiate it,
- // and then call its DrawObject() and TrackMouse() functions when needed.
- // When calling the drawing and mouse tracking functions (and this includes
- // functions where you set an attribute with redraw set to true), you must
- // ensure that the GrafPort and coordinate system are correct prior to the
- // call.
- //
- // Public functions:
- // - AGAObject. You supply its coordinate boundary.
- // - GetObjectBounds. Returns its coordinate boundary.
- // - SetObjectBounds. Call this to change its coordinate boundary.
- // - DrawObject. Draws the object. Assumes current port, pen normal.
- // - ContainsMouse. Returns true if specified mouse would hit it.
- // - TrackMouse. Handles a mouse click. Returns true if hit did something.
- // - SetEnable. Enables or disables it.
- // - SetBackgroundEraseColor. Sets the color the object will use when erasing its background.
- //
- // You can #define AGA_SUPERCLASS to be TObject or whatever
- // if you prefer to have the AGA stuff not be its own root
- // class hierarchy.
- //
-
- class AGAObject
-
- #ifdef AGA_SUPERCLASS
- : public AGA_SUPERCLASS
- #endif // AGA_SUPERCLASS
-
- {
- public:
-
- AGAObject(Rect* bounds);
- virtual ~AGAObject();
-
- virtual void GetObjectBounds(Rect* bounds);
- virtual void SetObjectBounds(Rect* bounds, Boolean redraw);
- virtual void DrawObject();
- virtual Boolean ContainsMouse(Point mouseLocation);
- virtual Boolean TrackMouse(Point mouseLocation);
- virtual void SetEnable(Boolean isEnabled, Boolean redraw);
- virtual void SetBackgroundEraseColor(RGBColor* color);
-
- enum { kRedraw = TRUE, kDontRedraw = FALSE };
- enum { kEnabled = TRUE, kDisabled = FALSE };
- enum { kPressed = TRUE, kNotPressed = FALSE };
- enum { kFrameInside = TRUE, kFrameOutside = FALSE };
- enum { kIsDefault = TRUE, kIsNotDefault = FALSE };
- enum { kAutomaticState = TRUE, kNoAutomaticState = FALSE };
- enum { kLiveTracking = TRUE, kNoLiveTracking = FALSE };
- enum { kProportional = TRUE, kNotProportional = FALSE };
- enum { kHorizontal = TRUE, kVertical = FALSE };
- enum { kTrackingIn = TRUE, kTrackingOut = FALSE };
-
- protected:
-
- // HitTest and SetTrackingState are called repeatedly by the default
- // mouse tracker.
- virtual Boolean HitTest(Point mouseLocation);
- virtual void SetTrackingState(Boolean isIn);
-
- Rect mBounds;
- Boolean mEnabled;
- RGBColor mBackgroundEraseColor;
- };
-
- //
- // MExclusiveObject ---------------------------------------------------------------
- //
- // MExclusiveObject is a mixin class for automatically keeping several
- // objects in a group mutually exclusive. The radio button class below
- // uses this to allow automatic radio button group behavior. MExclusiveObject
- // maintains knowledge of "groups" of objects. When one member of the group is
- // "hit", the other members of the group are sent the TurnOff() message. To
- // identify each object uniquely, the object has a pair of 32-bit identifiers.
- // Typically these can set to the group's ID and GrafPtr. This allows having
- // multiple windows that use the same group IDs. If you set the IDs to kNoGroupID,
- // then this automatic maintenance is bypassed.
- //
-
- class MExclusiveObject
- {
- public:
-
- MExclusiveObject(UInt32 groupIDPart1, UInt32 groupIDPart2);
- virtual ~MExclusiveObject();
-
- virtual void TurnOff();
-
- UInt32 mGroupIDPart1;
- UInt32 mGroupIDPart2;
- };
-
- const UInt32 kNoGroupID = 0xFFFFFFFF;
-
- //
- // AGATextStyle ---------------------------------------------------------------
- //
- // Many of the controls can have their text style specified. AGATextStyle
- // is used for this. It defines the font, size, and style to be used for
- // drawing text.
- //
-
- class AGATextStyle
- {
- public:
-
- AGATextStyle();
- AGATextStyle(SInt16 fontNum, SInt16 fontSize, Style fontStyle);
- AGATextStyle(StringPtr fontName, SInt16 fontSize, Style fontStyle);
- AGATextStyle(const TextStyle& textStyle);
-
- #ifdef __PowerPlant__
- AGATextStyle(ResIDT inTextTraitsID);
- #endif // __PowerPlant__
-
- void PrepareForDrawing() const;
-
- SInt16 mFontNum;
- SInt16 mFontSize;
- Style mFontStyle;
- };
-
- // These globals should be used in most cases. You can also roll your own.
- extern AGATextStyle gAGAStdSystemStyle; // Typically Chicago 12. Standard.
- extern AGATextStyle gAGAStdSmallStyle; // Typically Geneva 10. Slider labels.
- extern AGATextStyle gAGAExtraSmallStyle; // Typically Geneva 9. Use where you need a small control.
-
- //
- // AGAStaticText ---------------------------------------------------------------
- //
- // AGAStaticText draws a static text string on a gray background.
- //
-
- class AGAStaticText : public AGAObject
- {
- public:
-
- AGAStaticText(Rect* bounds, const AGATextStyle& textStyle, SInt32 justification);
- AGAStaticText(Rect* bounds, const AGATextStyle& textStyle, SInt32 justification, StringPtr title);
- AGAStaticText(Rect* bounds, const AGATextStyle& textStyle, SInt32 justification, SInt16 stringListResourceID, SInt16 stringIndex);
- virtual ~AGAStaticText();
-
- virtual void DrawObject();
-
- virtual void SetTitle(StringPtr buttonTitle, Boolean redraw);
-
- protected:
-
- SInt32 mJustification;
- Str255 mTitle;
- AGATextStyle mTextStyle;
- };
-
- //
- // AGAPushButton ---------------------------------------------------------------
- //
- // AGAPushButton implements the standard AGA pushbutton. It automatically
- // draws the default button outline if you set its mIsDefault property
- // by calling SetDefault; you specify whether the outline is inside or
- // outside the object's mBounds.
- //
-
- class AGAPushButton : public AGAObject
- {
- public:
-
- AGAPushButton(Rect* bounds, const AGATextStyle& textStyle);
- AGAPushButton(Rect* bounds, const AGATextStyle& textStyle, StringPtr buttonTitle);
- AGAPushButton(Rect* bounds, const AGATextStyle& textStyle, SInt16 stringListResourceID, SInt16 stringIndex);
- virtual ~AGAPushButton();
-
- virtual void DrawObject();
-
- virtual void SetTitle(StringPtr buttonTitle, Boolean redraw);
-
- virtual void SetDefault(Boolean isDefault, Boolean frameInside);
-
- void DrawButton(Boolean pressed);
-
- protected:
-
- virtual Boolean HitTest(Point mouseLocation);
- virtual void SetTrackingState(Boolean isIn);
-
- virtual void DrawButtonNormal(Boolean deep);
- virtual void DrawButtonPressed(Boolean deep);
- virtual void DrawButtonDisabled(Boolean deep);
-
- void DrawOutlineNormal(Boolean deep);
- void DrawOutlineDisabled(Boolean deep);
-
- Boolean mIsDefault; // if TRUE this button gets a default frame
- Boolean mFrameInside; // if TRUE the frame is inside mBounds; else outside
- Str255 mTitle;
- AGATextStyle mTextStyle;
- };
-
- //
- // AGACheckBox ---------------------------------------------------------------
- //
- // AGACheckBox implements the standard AGA check box. It also supports
- // a mixed state that is neither on nor off, which is drawn as a dash.
- //
-
- class AGACheckBox : public AGAObject
- {
- public:
-
- enum { kCheckBoxSize = 12 };
- enum { kCheckBoxOff = 0, kCheckBoxOn = 1, kCheckBoxMixed = 2 };
-
- AGACheckBox(Rect* bounds, const AGATextStyle& textStyle, Boolean automaticState);
- AGACheckBox(Rect* bounds, const AGATextStyle& textStyle, StringPtr buttonTitle, Boolean automaticState);
- AGACheckBox(Rect* bounds, const AGATextStyle& textStyle, SInt16 stringListResourceID, SInt16 stringIndex, Boolean automaticState);
- virtual ~AGACheckBox();
-
- virtual void DrawObject();
- virtual Boolean TrackMouse(Point mouseLocation);
-
- virtual void SetTitle(StringPtr buttonTitle, Boolean redraw);
-
- virtual SInt32 GetValue();
- virtual void SetValue(SInt32 newValue, Boolean redraw);
-
- void DrawButton(Boolean pressed);
-
- protected:
-
- virtual void SetTrackingState(Boolean isIn);
-
- virtual void DrawButtonNormal(Boolean deep);
- virtual void DrawButtonPressed(Boolean deep);
- virtual void DrawButtonDisabled(Boolean deep);
-
- SInt32 mValue;
- Boolean mAutomaticState;
- Str255 mTitle;
- AGATextStyle mTextStyle;
- };
-
- //
- // AGAOffscreenImage ------------------------------------------------------------
- //
- // AGAOffscreenImage holds the data needed to blast a clipped region
- // of pixel values onto the current port. This is used by the AGARadioButton
- // class to avoid the ultra-tedious pixel-by-pixel drawing of the grayscale
- // radio button images.
- //
-
- class AGAOffscreenImage
-
- #ifdef AGA_SUPERCLASS
- : public AGA_SUPERCLASS
- #endif // AGA_SUPERCLASS
- {
- public:
-
- AGAOffscreenImage();
- virtual ~AGAOffscreenImage();
-
- virtual OSErr CreateImageData(Point imageSize,
- SInt8* imageColorIndexes,
- RgnHandle clippingRegion);
-
- void DrawImage(SInt16 imageHOrigin, SInt16 imageVOrigin);
- void DrawPattern(Rect* imageRect);
-
- protected:
-
- Rect mImageSourceRect; // 0, 0, x, y
- PixMapHandle mImagePixMap;
- RgnHandle mClippingRegion;
- };
-
- //
- // AGARadioButton ---------------------------------------------------------------
- //
- // AGARadioButton implements the standard AGA radio button. It also supports
- // a mixed state that is neither on nor off, which is drawn as a dash.
- // You can also assign an ID pair that will be used to automatically keep
- // the radio button mutually exclusive with others with the same ID pair.
- // Pass kNoGroupID for the IDs to bypass this.
- //
-
- class AGARadioButton : public AGAObject, public MExclusiveObject
- {
- public:
-
- enum { kRadioButtonOff = 0, kRadioButtonOn = 1, kRadioButtonMixed = 2 };
-
- static OSErr AllocateRadioImages();
- static void DisposeRadioImages();
-
- AGARadioButton(Rect* bounds, const AGATextStyle& textStyle, UInt32 groupIDPart1, UInt32 groupIDPart2, Boolean automaticState);
- AGARadioButton(Rect* bounds, const AGATextStyle& textStyle, StringPtr buttonTitle, UInt32 groupIDPart1, UInt32 groupIDPart2, Boolean automaticState);
- AGARadioButton(Rect* bounds, const AGATextStyle& textStyle, SInt16 stringListResourceID, SInt16 stringIndex, UInt32 groupIDPart1, UInt32 groupIDPart2, Boolean automaticState);
- virtual ~AGARadioButton();
-
- virtual void DrawObject();
- virtual Boolean TrackMouse(Point mouseLocation);
-
- virtual void SetTitle(StringPtr buttonTitle, Boolean redraw);
-
- virtual SInt32 GetValue();
- virtual void SetValue(SInt32 newValue, Boolean redraw);
-
- virtual void TurnOff(); // MExclusiveObject override
-
- void DrawButton(Boolean pressed);
-
- protected:
-
- virtual void SetTrackingState(Boolean isIn);
-
- virtual void DrawButtonNormal(Boolean deep);
- virtual void DrawButtonPressed(Boolean deep);
- virtual void DrawButtonDisabled(Boolean deep);
-
- void CopyImage(UInt32 index);
-
- SInt32 mValue;
- Boolean mAutomaticState;
- UInt32 mGroupID;
- Str255 mTitle;
- AGATextStyle mTextStyle;
-
- // Drawing the 3D radio button manually is just too damn tedious.
- // So we use offscreen PixMap structures and blast them onto the screen.
- // The mask (clip) region for the images is a round rectangle.
-
- enum { kRadioImageWidth = 12, kRadioImageHeight = 12 };
- enum { kRadioNormalOff, kRadioNormalOn, kRadioNormalMixed,
- kRadioPressedOff, kRadioPressedOn, kRadioPressedMixed,
- kRadioDisabledOff, kRadioDisabledOn, kRadioDisabledMixed,
- kNumRadioImages };
-
- static SInt8 kRadioImageValues[kNumRadioImages]
- [kRadioImageHeight]
- [kRadioImageWidth];
-
- static AGAOffscreenImage* mgOffscreenRadioImages[kNumRadioImages];
- };
-
- //
- // MIconButtonObject ---------------------------------------------------------------
- //
- // MIconButtonObject is a mixin class for the classes that have an
- // icon button appearance. There are 3 different "types" of icon button,
- // differening only the details of the button edge appearance. The type
- // is determined by the button size, but you can explicitly set it with
- // the SetIconType function. An icon button has two icon IDs. Usually
- // these are the same, but for some button types you can make them
- // different. For example, if you want different icons for on/off when
- // the button is used as a radio button or check box.
- //
- // Ideal button sizes, to match AGA specification:
- // - Large icon button: 40x40 (32x32 iclx plus 4 pixel border on each side)
- // - Small icon button: 22x22 (16x16 icsx plus 3 pixel border on each side)
- // - Mini icon button: 16x16 (12x12 icmx plus 2 pixel border on each side)
- // Note that mini icons are a rather rare resource that ResEdit 2.x doesn't grok.
- //
-
- class MIconButtonObject
- {
- public:
-
- enum { kNoIconID = 0 };
- enum { kMiniIcon = 0, kSmallIcon = 1, kLargeIcon = 2 };
-
- MIconButtonObject();
- MIconButtonObject(SInt16 offIconID, SInt16 onIconID, UInt32 iconType);
- virtual ~MIconButtonObject();
-
- void SetIconIDs(SInt16 offIconID, SInt16 onIconID);
- void SetIconType(UInt32 iconType);
-
- virtual void DrawIconButton(Rect* bounds,
- Boolean isOn,
- Boolean isPressed,
- Boolean isEnabled,
- Boolean deep);
-
- static UInt32 GetDefaultIconType(SInt16 buttonWidth);
-
- protected:
-
- virtual void DrawMiniEdges(Rect* bounds, Boolean isOn, Boolean isPressed, Boolean isEnabled, Boolean deep);
- virtual void DrawSmallEdges(Rect* bounds, Boolean isOn, Boolean isPressed, Boolean isEnabled, Boolean deep);
- virtual void DrawLargeEdges(Rect* bounds, Boolean isOn, Boolean isPressed, Boolean isEnabled, Boolean deep);
-
- SInt16 mOffIconID;
- SInt16 mOnIconID;
- UInt32 mIconType;
- };
-
- //
- // AGAIconPushButton ---------------------------------------------------------------
- //
- // AGAIconPushButton implements the standard AGA icon button, with
- // pushbutton behavior; that is to say, it has no state. This is
- // done by subclassing AGAPushButton for tracking, and mixing in
- // MIconButtonObject for drawing.
- //
-
- class AGAIconPushButton : public AGAPushButton, public MIconButtonObject
- {
- public:
-
- AGAIconPushButton(Rect* bounds);
- AGAIconPushButton(Rect* bounds, SInt16 iconID, UInt32 iconType);
- virtual ~AGAIconPushButton();
-
- protected:
-
- virtual void DrawButtonNormal(Boolean deep);
- virtual void DrawButtonPressed(Boolean deep);
- virtual void DrawButtonDisabled(Boolean deep);
- };
-
- //
- // AGAIconCheckBox ---------------------------------------------------------------
- //
- // AGAIconCheckBox implements the standard AGA icon button, with
- // check box behavior; that is to say, it has an on or off state
- // that toggles when hit. This is done by subclassing AGACheckBox
- // for tracking and state, and mixing in MIconButtonObject for drawing.
- //
-
- class AGAIconCheckBox : public AGACheckBox, public MIconButtonObject
- {
- public:
-
- AGAIconCheckBox(Rect* bounds, Boolean automaticState);
- AGAIconCheckBox(Rect* bounds, Boolean automaticState, SInt16 offIconID, SInt16 onIconID, UInt32 iconType);
- virtual ~AGAIconCheckBox();
-
- protected:
-
- virtual void DrawButtonNormal(Boolean deep);
- virtual void DrawButtonPressed(Boolean deep);
- virtual void DrawButtonDisabled(Boolean deep);
- };
-
- //
- // AGAIconRadioButton ---------------------------------------------------------------
- //
- // AGAIconRadioButton implements the standard AGA icon button, with
- // radio button behavior; that is to say, it has an on or off state
- // that can be automatically made mutually exclusive with other
- // buttons in its group. This is done by subclassing AGARadioButton
- // for tracking and state, and mixing in MIconButtonObject for drawing.
- //
-
- class AGAIconRadioButton : public AGARadioButton, public MIconButtonObject
- {
- public:
-
- AGAIconRadioButton(Rect* bounds, UInt32 groupIDPart1, UInt32 groupIDPart2, Boolean automaticState);
- AGAIconRadioButton(Rect* bounds, UInt32 groupIDPart1, UInt32 groupIDPart2, Boolean automaticState, SInt16 offIconID, SInt16 onIconID, UInt32 iconType);
- virtual ~AGAIconRadioButton();
-
- protected:
-
- virtual void DrawButtonNormal(Boolean deep);
- virtual void DrawButtonPressed(Boolean deep);
- virtual void DrawButtonDisabled(Boolean deep);
- };
-
- class AGATrackingIndicator;
-
- // This is the live tracking notification prototype for AGATrackingIndicator.
- typedef void (*AGATrackingIndicatorNotifyPtr)(AGATrackingIndicator* theIndicator, SInt32 itsNewValue, void* userData);
-
- //
- // AGATrackingIndicator ---------------------------------------------------------------
- //
- // AGATrackingIndicator is the abstract superclass for things like
- // sliders and scroll bars that have a moving indicator to reflect
- // the object's position. It has a minimum/maximum range, a current
- // value, and optionally a page size for proportional indicator
- // display. You can turn live tracking on or off; if live tracking
- // is off, a "ghost" indicator is dragged and no notification occurs
- // until the tracking completes.
- //
-
- class AGATrackingIndicator : public AGAObject
- {
- public:
-
- AGATrackingIndicator(Rect* bounds, SInt32 minimum, SInt32 maximum, SInt32 initialValue);
- AGATrackingIndicator(Rect* bounds, SInt32 minimum, SInt32 maximum, SInt32 initialValue, SInt32 pageSize, Boolean liveTracking, Boolean proportional);
- virtual ~AGATrackingIndicator();
-
- virtual void InstallNotificationRoutine(AGATrackingIndicatorNotifyPtr notificationRoutine, void* userData);
-
- virtual void SetAttributes(Boolean isHorizontal, Boolean liveTracking, Boolean isProportional);
-
- virtual void DrawObject();
- virtual Boolean TrackMouse(Point mouseLocation);
-
- virtual SInt32 GetValue();
- virtual void SetValue(SInt32 newValue, Boolean redraw);
-
- virtual void GetRange(SInt32* minimum, SInt32* maximum);
- virtual void SetRange(SInt32 newMinimum, SInt32 newMaximum, Boolean redraw);
-
- virtual SInt32 GetPageSize();
- virtual void SetPageSize(SInt32 newPageSize, Boolean redraw);
-
- protected:
-
- enum { kNoTrackPress, kPageMinusPress, kArrowMinusPress, kIndicatorPress, kArrowPlusPress, kPagePlusPress };
-
- virtual Boolean TrackPart(Point mouseLocation, SInt32 partHit);
- virtual SInt32 TrackTestPart(Point mouseLocation);
- virtual Boolean IsValidIndicatorTrackMouse(Point mouseLocation);
- virtual SInt32 GetValueFromMouseDelta(SInt32 originalValue, Point originalMouseLocation, Point newMouseLocation);
- virtual void SetGhostValue(SInt32 newValue, Boolean redraw);
-
- virtual void DrawBackground();
- virtual void DrawIndicatorTrack();
- virtual void DrawTrackEnds();
- virtual void DrawIndicator();
- virtual void RemoveIndicator(SInt32 newValue);
- virtual void DrawGhost();
- virtual void RemoveGhost(SInt32 newValue);
-
- virtual void NotifyValue();
-
- SInt32 mMinimum;
- SInt32 mMaximum;
- SInt32 mValue;
- SInt32 mPageSize;
- SInt32 mGhostValue;
- Boolean mLiveTracking;
- Boolean mIsProportional;
- Boolean mIsHorizontal;
- Boolean mIsPressed;
-
- AGATrackingIndicatorNotifyPtr mNotificationRoutine;
- void* mUserData;
- };
-
- //
- // AGAScrollBar ---------------------------------------------------------------
- //
- // AGAScrollBar implements the standard AGA scroll bar. It also supports
- // live indicator tracking and a proportional indicator as options.
- //
-
- class AGAScrollBar : public AGATrackingIndicator
- {
- public:
-
- AGAScrollBar(Rect* bounds, SInt32 minimum, SInt32 maximum, SInt32 initialValue);
- AGAScrollBar(Rect* bounds, SInt32 minimum, SInt32 maximum, SInt32 initialValue, SInt32 singleStepSize, SInt32 pageStepSize, SInt32 pageSize, Boolean liveTracking, Boolean proportional);
- virtual ~AGAScrollBar();
-
- virtual void SetStepSizes(SInt32 singleStepSize, SInt32 pageStepSize);
- virtual void Activate(Boolean activateState, Boolean redraw);
-
- protected:
-
- virtual Boolean TrackPart(Point mouseLocation, SInt32 partHit);
- virtual SInt32 TrackTestPart(Point mouseLocation);
- virtual Boolean IsValidIndicatorTrackMouse(Point mouseLocation);
- virtual SInt32 GetValueFromMouseDelta(SInt32 originalValue, Point originalMouseLocation, Point newMouseLocation);
-
- virtual void DrawIndicatorTrack();
- virtual void DrawTrackEnds();
- virtual void DrawIndicator();
- virtual void RemoveIndicator(SInt32 newValue);
- virtual void DrawGhost();
- virtual void RemoveGhost(SInt32 newValue);
-
- virtual void TrackDelta(SInt32 partHit);
-
- virtual void DrawArrow(SInt32 arrowPart, Boolean pressed);
-
- enum { kIndicatorPixelInset = 8 };
- enum { kArrowSize = 16 };
-
- virtual void GetIndicatorBox(SInt32 value, Rect* indicatorBox);
- virtual SInt32 GetIndicatorPixelRange(SInt32* proportionalIndicatorPixels);
- virtual void GetIndicatorPixelEnds(SInt32* startPt, SInt32* stopPt);
- virtual void GetIndicatorSpan(SInt32 value, SInt32* startPt, SInt32* valuePt, SInt32* stopPt);
-
- SInt32 mSingleStepSize; // amount to delta for arrow tracking
- SInt32 mPageStepSize; // amount to delta for page tracking
- Boolean mActive; // inactive windows have inactive scroll bars
-
- // These regions are used by RemoveIndicator and RemoveGhost.
- // They are tiny but we allocate them statically to avoid
- // repeated allocation, which could conceivably fail.
- static RgnHandle mgSavedIndicatorClip;
- static RgnHandle mgOldIndicatorClip;
- static RgnHandle mgNewIndicatorClip;
- };
-
- //
- // AGASlider ---------------------------------------------------------------
- //
- // AGASlider implements the standard AGA slider. You specify whether it
- // is horizontal or vertical, labeled or unlabeled, rectangular or pointy.
- // By default, if you specify a labeled slider, it is pointy; otherwise it
- // is rectangular. You can change this by calling SetSliderKind, and you
- // can set the labels up after construction by calling the label functions.
- // It also supports live indicator tracking and a proportional indicator
- // as options.
- //
-
- class AGASlider : public AGATrackingIndicator
- {
- public:
-
- enum SliderKind { kRectSlider, kPointerSlider };
-
- AGASlider(Rect* bounds, SInt32 minimum, SInt32 maximum, SInt32 initialValue, const AGATextStyle& textStyle, SInt16 labelsID);
- AGASlider(Rect* bounds, SInt32 minimum, SInt32 maximum, SInt32 initialValue, const AGATextStyle& textStyle, SInt16 labelsID, SliderKind kind, Boolean liveTracking, Boolean proportional);
- virtual ~AGASlider();
-
- virtual void SetSliderKind(SliderKind kind);
- virtual void SetLabelsFromResource(SInt16 stringListResourceID);
- virtual void SetNumLabels(UInt32 numLabels);
- virtual void SetLabel(UInt32 labelIndex, StringPtr itsLabel);
- virtual void GetLabel(UInt32 labelIndex, StringPtr itsLabel);
- virtual void SetLabelsStyle(const AGATextStyle& textStyle);
- virtual void SetJustification(SInt32 justification);
-
- protected:
-
- virtual SInt32 TrackTestPart(Point mouseLocation);
- virtual Boolean IsValidIndicatorTrackMouse(Point mouseLocation);
- virtual SInt32 GetValueFromMouseDelta(SInt32 originalValue, Point originalMouseLocation, Point newMouseLocation);
-
- virtual void DrawBackground();
- virtual void DrawIndicatorTrack();
- virtual void DrawIndicator();
- virtual void RemoveIndicator(SInt32 newValue);
- virtual void DrawGhost();
- virtual void RemoveGhost(SInt32 newValue);
-
- enum { kRectIndicatorPixelInset = 6 };
- enum { kPointerIndicatorPixelInset = 7 };
- enum { kIndicatorWidth = 16 };
- enum { kEndGapSize = 5 };
- enum { kLabelTickEndInset = 11};
- enum { kLabelTickOffset = 8};
- enum { kLabelPosTextOffset = 14};
- enum { kLabelNegTextOffset = 8};
- enum { kLabelTickLength = 6};
- enum { kGhostIndicator = TRUE, kNormalIndicator = FALSE };
- enum { kIncludeBackground = TRUE, kTrackOnly = FALSE };
-
- virtual void GetTrackFrame(Rect* trackFrame, Boolean includeBackground);
- virtual void GetIndicatorBox(SInt32 value, Rect* indicatorBox);
- virtual SInt32 GetIndicatorPixelRange(SInt32* proportionalIndicatorPixels);
- virtual void GetIndicatorPixelEnds(SInt32* startPt, SInt32* stopPt);
- virtual void GetIndicatorSpan(SInt32 value, SInt32* startPt, SInt32* valuePt, SInt32* stopPt);
-
- virtual void DrawLabels();
- virtual void DrawRectIndicator(Rect* indicatorRect, Boolean isGhost);
- virtual void DrawPointerIndicator(Rect* indicatorRect, Boolean isGhost);
- virtual void BuildPointerIndicator(Rect* indicatorRect);
-
- virtual void DisposeLabels();
-
- Handle mLabelStringHandles; // an array of StringHandle, may be NULL
- SInt32 mJustification;
- SliderKind mSliderKind;
- AGATextStyle mTextStyle;
-
- // These regions are used by RemoveIndicator and RemoveGhost.
- // They are tiny but we allocate them statically to avoid
- // repeated allocation, which could conceivably fail.
- static RgnHandle mgSavedIndicatorClip;
- static RgnHandle mgOldIndicatorClip;
- static RgnHandle mgNewIndicatorClip;
- };
-
- //
- // AGAPopupMenu ---------------------------------------------------------------
- //
- // AGAPopupMenu implements the standard AGA pop-up menu. You can specify
- // whether the supplied boundary is fixed or whether the pop-up button
- // should adapt its width to the width of the associated menu. You can
- // also supply a title to be drawn next to the pop-up button.
- //
-
- class AGAPopupMenu : public AGAObject
- {
- public:
-
- enum WidthAdjust { kFixedWidth = -1, kUseMenuWidth = 0, kSystemMDEFAdjustment = 19 };
- enum DisposalKind { kDontDispose, kDispose, kRelease };
-
- AGAPopupMenu(Rect* bounds, SInt16 titleOffset, StringPtr title, SInt32 titleJustification, const AGATextStyle& textStyle, WidthAdjust adjustment);
- AGAPopupMenu(Rect* bounds, SInt16 titleOffset, StringPtr title, SInt32 titleJustification, const AGATextStyle& textStyle, WidthAdjust adjustment, MenuRef itsMenuRef, DisposalKind menuRefDisposalKind);
- AGAPopupMenu(Rect* bounds, SInt16 titleOffset, StringPtr title, SInt32 titleJustification, const AGATextStyle& textStyle, WidthAdjust adjustment, SInt16 itemsStringListID, SInt16 newMenuID);
- AGAPopupMenu(Rect* bounds, SInt16 titleOffset, StringPtr title, SInt32 titleJustification, const AGATextStyle& textStyle, WidthAdjust adjustment, ResType appendResourceType, SInt16 newMenuID);
- virtual ~AGAPopupMenu();
-
- virtual void SetMenuRef(MenuRef itsMenuRef, DisposalKind menuRefDisposalKind);
- virtual void SetWidthAdjustment(WidthAdjust adjustment);
-
- virtual void DrawObject();
- virtual Boolean TrackMouse(Point mouseLocation);
-
- virtual SInt16 GetCurrentItemNo();
- virtual void SetCurrentItemNo(SInt16 newItemNo, Boolean redraw);
-
- virtual void GetCurrentItemText(StringPtr itemText);
- virtual Boolean SetCurrentItemText(StringPtr itemTextToMatch, Boolean redraw); // returns FALSE if no match found
-
- void DrawButton(Boolean pressed);
-
- protected:
-
- virtual void DrawButtonNormal(Boolean deep);
- virtual void DrawButtonPressed(Boolean deep);
- virtual void DrawButtonDisabled(Boolean deep);
- virtual void GetButtonBounds(Rect* buttonBounds);
- virtual void GetTitleBounds(Rect* titleBounds);
-
- virtual void DisposeExistingMenuRef();
-
- enum { kPopupArrowSectionWidth = 22 };
-
- SInt16 mMenuID;
- MenuRef mMenuRef;
- DisposalKind mMenuRefDisposalKind;
- SInt16 mCurrentItemNo;
- WidthAdjust mWidthAdjust;
- AGATextStyle mTextStyle;
- Str255 mTitle;
- SInt16 mTitleOffset;
- SInt32 mTitleJustification;
- };
-
- class AGALittleArrows;
-
- // This is the live tracking notification prototype for AGALittleArrows.
- typedef void (*AGALittleArrowsNotifyPtr)(AGALittleArrows* theIndicator, SInt32 pressedPart, void* userData);
-
- //
- // AGALittleArrows ---------------------------------------------------------------
- //
- // AGALittleArrows implements the standard AGA little arrows. To respond
- // to continuous messages during tracking, you should either install a
- // notification routine or subclass and override NotifyDelta. The supplied
- // MacApp and PowerPlant classes do this for you.
- //
-
- class AGALittleArrows : public AGAObject
- {
- public:
-
- enum { kDownArrowPressed = -1, kNoArrowPressed = 0, kUpArrowPressed = 1 };
-
- AGALittleArrows(Rect* bounds);
- virtual ~AGALittleArrows();
-
- virtual void InstallNotificationRoutine(AGALittleArrowsNotifyPtr notificationRoutine, void* userData);
-
- virtual void DrawObject();
- virtual Boolean TrackMouse(Point mouseLocation);
-
- void DrawButton(SInt32 pressedPart);
-
- protected:
-
- enum { kLittleArrowWidth = 13, kLittleArrowHeight = 12, kLittleArrowTotalHeight = 23 };
-
- virtual Boolean TrackPart(Point mouseLocation, SInt32 partHit);
- virtual SInt32 TrackTestPart(Point mouseLocation);
-
- virtual void NotifyDelta(SInt32 partHit);
-
- AGALittleArrowsNotifyPtr mNotificationRoutine;
- void* mUserData;
- };
-
- //
- // AGADisclosureTriangle ---------------------------------------------------------------
- //
- // AGADisclosureTriangle implements the standard AGA disclosure triangle.
- // You can think of it as a check box that is either off (closed) or on
- // (disclosed).
- //
-
- class AGADisclosureTriangle : public AGAObject
- {
- public:
-
- enum { kDisclosedState = TRUE, kClosedState = FALSE };
-
- AGADisclosureTriangle(Rect* bounds, Boolean automaticState);
- virtual ~AGADisclosureTriangle();
-
- virtual void DrawObject();
- virtual Boolean TrackMouse(Point mouseLocation);
-
- virtual Boolean GetState();
- virtual void SetState(Boolean isDisclosed, Boolean redraw);
- virtual void SetStateAnimate(Boolean isDisclosed);
-
- protected:
-
- virtual void SetTrackingState(Boolean isIn);
-
- enum DTAnimationState { kDTClosed, kDTPressedClosed, kDTIntermediate, kDTPressedDisclosed, kDTDisclosed };
-
- void DrawTriangle(DTAnimationState state);
- void EraseBackground();
-
- Boolean mAutomaticState;
- Boolean mIsDisclosed;
- };
-
- //
- // AGAProgressIndicator ---------------------------------------------------------------
- //
- // AGAProgressIndicator implements the standard AGA progress indicator.
- // It can be determinate (a moving gauge) or indeterminate (a rotating
- // barber pole). In addition, it supports a "moving origin", which is
- // where, in addition to moving the gauge end point, the gauge start
- // point also moves.
- //
-
- class AGAProgressIndicator : public AGAObject
- {
- public:
-
- static OSErr AllocateProgressImages();
- static void DisposeProgressImages();
-
- AGAProgressIndicator(Rect* bounds, SInt32 minimum, SInt32 maximum);
- virtual ~AGAProgressIndicator();
-
- virtual void DrawObject();
-
- virtual SInt32 GetValue();
- virtual void SetValue(SInt32 newValue, Boolean redraw);
- virtual void Increment(SInt32 delta, Boolean redraw);
-
- virtual void Animate();
-
- virtual void GetRange(SInt32* minimum, SInt32* maximum);
- virtual void SetRange(SInt32 newMinimum, SInt32 newMaximum, Boolean redraw);
-
- virtual SInt32 GetOriginValue();
- virtual void SetOriginValue(SInt32 newValue, Boolean redraw);
-
- protected:
-
- virtual void DrawFrame();
- virtual void DrawAnimationStep();
- virtual void DrawGauge();
- virtual void DrawOriginArea();
- virtual void DrawProgressArea();
- virtual void DrawRemainderArea();
-
- virtual Boolean GetOriginFrame(Rect* originFrame);
- virtual Boolean GetProgressFrame(Rect* progressFrame);
- virtual Boolean GetRemainderFrame(Rect* remainderFrame);
- virtual void GetRangeFrame(SInt32 startValue, SInt32 endValue, Rect* rangeFrame);
-
- enum { kProgressHeight = 14 };
- enum { kProgressImageHeight = 10, kProgressImageWidth = 16 };
- enum { k1BitPattern, kDeepPattern, kNumProgressPatterns };
- enum { kNumProgressAnimationSteps = 4 }; // 2, 4, 8, or 16 will work
-
- SInt32 mMinimum;
- SInt32 mMaximum;
- SInt32 mValue;
- SInt32 mOriginValue; // usually == mMinimum
- UInt32 mAnimationIndex;
-
- static SInt8 kIndeterminateProgressImage[kNumProgressPatterns]
- [kProgressImageHeight]
- [kProgressImageWidth];
-
- static AGAOffscreenImage* mgOffscreenIndeterminateProgressImage[kNumProgressPatterns];
- };
-
- //
- // AGASeparator ---------------------------------------------------------------
- //
- // AGASeparator implements the standard AGA separator line.
- // It automatically determines its orientation based on the coordinate
- // bounding box dimensions.
- //
-
- class AGASeparator : public AGAObject
- {
- public:
-
- AGASeparator(Rect* bounds);
- virtual ~AGASeparator();
-
- virtual void DrawObject();
- };
-
- //
- // AGAGroupBox ---------------------------------------------------------------
- //
- // AGAGroupBox implements the standard AGA group box. A group box
- // can either be primary or secondary. Secondary group boxes should
- // be used inside primary group boxes. You can supply a title string
- // for the group box, or you can specify a "gap" width that is to
- // be left blank to make room for a control or title string that will
- // be drawn elsewhere.
- //
-
- class AGAGroupBox : public AGAObject
- {
- public:
-
- enum { kPrimaryGroupBox = TRUE, kSecondaryGroupBox = FALSE };
-
- AGAGroupBox(Rect* bounds, const AGATextStyle& textStyle, Boolean groupBoxType);
- AGAGroupBox(Rect* bounds, const AGATextStyle& textStyle, Boolean groupBoxType, SInt16 titleGap);
- AGAGroupBox(Rect* bounds, const AGATextStyle& textStyle, Boolean groupBoxType, StringPtr titleString);
- AGAGroupBox(Rect* bounds, const AGATextStyle& textStyle, Boolean groupBoxType, SInt16 titleStringListResourceID, SInt16 titleStringIndex);
- virtual ~AGAGroupBox();
-
- virtual void SetTitleGap(SInt16 titleGap);
- virtual void SetTitle(StringPtr newTitle, Boolean redraw);
-
- virtual void DrawObject();
-
- protected:
-
- virtual void DrawPrimaryFrame(SInt16 topIndent, SInt16 gapSize);
- virtual void DrawSecondaryFrame(SInt16 topIndent, SInt16 gapSize);
-
- Boolean mIsPrimaryBox;
- SInt16 mTitleGap; // horizontal gap for other object in title, no top indent
- Str255 mTitle; // zero-length string indicates no title, no top indent
- AGATextStyle mTextStyle;
- };
-
- //
- // GDIterator -----------------------------------------------------
- //
- // To properly handle drawing in grayscale with multiple monitors
- // and differing color depths, we must draw while iterating over
- // the GD handles. This iterator makes a for loop easy while also
- // reducing the clipping area to the appropriate device and setting
- // a boolean to indicate whether the device is "deep" or not. "Deep"
- // meaning suitable for grayscale drawing as opposed to black & white.
- //
-
- class GDIterator
- {
- public:
-
- GDIterator();
- virtual ~GDIterator();
-
- void Setup(); // called by constructor; can be called again
- Boolean More(Boolean& deep);// returns true while you should draw again
- void Cleanup(); // called by destructor; can be called earlier
-
- void ClipFurtherToCurrentDevice(); // can be called for tricky clipping situations (see slider labels)
-
- protected:
-
- GDHandle FindNextValidDevice(GDHandle currentDevice, Boolean& deep);
- void ClipFurtherToDevice(GDHandle aDevice);
-
- Boolean mIteratedYet;
- GDHandle mCurrentGDHandle; // inited by Setup, changed by More
-
- static RgnHandle mSavedClipping; // saved by Setup, restored by Cleanup
- };
-
- //
- // AGAGroupsContainer --------------------------------------------------------
- //
- // This class is used internally to maintain the MExclusiveObject
- // behavior that allows radio buttons to automatically maintain
- // standard radio button group XOR behavior.
- //
-
- typedef struct
- {
- UInt32 mGroupIDPart1;
- UInt32 mGroupIDPart2;
- vector<MExclusiveObject*> mGroupMembers;
- } AGAGroup;
-
- class AGAGroupsContainer
-
- #ifdef AGA_SUPERCLASS
- : public AGA_SUPERCLASS
- #endif // AGA_SUPERCLASS
-
- {
- public:
-
- void AGAAddGroupMember(MExclusiveObject* groupMember);
- void AGARemoveGroupMember(MExclusiveObject* groupMember);
- void AGAHitGroupMember(MExclusiveObject* groupMember);
-
- protected:
-
- AGAGroup* FindGroup(MExclusiveObject* groupMember);
- MExclusiveObject** FindMemberPtr(AGAGroup* itsGroup, MExclusiveObject* groupMember);
-
- vector<AGAGroup> mGroups;
- };
-
- //
- // These are the gAGARamp RGB color value indexes.
- // They match the numbers specified in the AGA doc.
- // rW is white.
- // 1 thru 12 go from light gray to dark gray, matching AGA doc indexes.
- // rA is the additional dark gray in the indeterminate progress pattern.
- // rB is black.
- // rA1 thru rA4 are the purple shades for the disclosure triangle.
- //
-
- typedef enum
- {
- rW = 0,
- r1 = 1,
- r2 = 2,
- r3 = 3,
- r4 = 4,
- r5 = 5,
- r6 = 6,
- r7 = 7,
- r8 = 8,
- r9 = 9,
- r10 = 10,
- r11 = 11,
- r12 = 12,
- rA = 13,
- rB = 14,
- rA1 = 15,
- rA2 = 16,
- rA3 = 17,
- rA4 = 18,
-
- kNumRampColors,
-
- OUT = -1
- } RampIndex;
-
- extern RGBColor gAGARamp[kNumRampColors];
- extern Boolean gAGAHasColorQD;
- extern const Str255 gGrayCouncilCopyright;
-
- extern void SetGrayCouncilDefault(UInt32 itemMask, Boolean turnOn);
- extern Boolean TestGrayCouncilDefault(UInt32 itemMask);
-
- #define kAGALiveScrolling 0x00000001
- #define kAGAProportionalScrolling 0x00000002
- #define kAGALiveRSliders 0x00000004
- #define kAGAProportionalRSliders 0x00000008
- #define kAGALivePSliders 0x00000010
- #define kAGAProportionalPSliders 0x00000020
-
- #define kNoTruncation -1
-
- enum AGAStringOutColor { kNormalOutput, kDisabledOutput, kInverseOutput, kUseCurrentColor };
-
- extern void AGAStringOut(StringPtr aString,
- Rect* centeringFrame,
- SInt32 truncation,
- SInt32 justification,
- AGAStringOutColor outColor,
- Boolean deep,
- const AGATextStyle& textStyle);
-
- enum { kIsModal = TRUE, kIsNotModal = FALSE };
- extern void AGABackgroundPaint(const Rect* backgroundBounds,
- Boolean drawFill,
- Boolean isModal,
- Boolean isActive,
- Boolean hasGrowBox);
-
- extern void AGAClipFurther(Rect* clippingRect);
- extern void CleansePen();
-
- #endif // __GRAYCOUNCIL__
-
-